package com.gnerv.plug.note.data;

import com.gnerv.plug.note.entity.NoteInfo;
import com.gnerv.plug.note.ui.NoteToolWindow;
import org.apache.commons.lang.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;

public class DataCenter {

    public static final String[] HEADERS = {"ukId", "title", "content"};

    public static Map<String, NoteInfo> NOTE_DATA = new LinkedHashMap<>(32);

    public static NoteToolWindow NOTE_TOOL_WINDOW = new NoteToolWindow();

    public static void refreshToolWindowTableData(String title) {
        NOTE_TOOL_WINDOW.getModel().setRowCount(0);
        if (StringUtils.isEmpty(title)) {
            for (NoteInfo noteInfo : NOTE_DATA.values()) {
                NOTE_TOOL_WINDOW.addData(noteInfo);
            }
        } else {
            for (NoteInfo noteInfo : NOTE_DATA.values()) {
                if(noteInfo.getTitle().indexOf(title) != -1){
                    NOTE_TOOL_WINDOW.addData(noteInfo);
                }
            }
        }
    }

}
